package com.imcode;

import java.io.*;

/**
 * 文件复制
 */
public class FileCopy01 {

    public static void main(String[] args) {
        InputStream in = null;
        OutputStream out = null;
        try {
            //1.读取D盘1.png的内容，创建一个文件输入流
            in = new FileInputStream("D:\\file\\1.txt");
            out = new FileOutputStream("D:\\file\\2.txt");
            //2.定义一个字节数组
            byte[] bytes = new byte[5];
            int len = 0;
            while ((len = in.read(bytes)) != -1) {
                //3.将读取到的内容写入到E盘1.png
                //System.out.println(new String(bytes,0,len));
                out.write(bytes, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
